//
//  AppDelegate.m
//  ArtCircle
//
//  Created by sunbin on 2017/5/19.
//  Copyright © 2017年 HuaYue. All rights reserved.
//

#import "AppDelegate.h"
#import "AppConfig.h"

#import <UserNotifications/UserNotifications.h>

#import "AppDelegate+EaseMob.h"
@interface AppDelegate ()<UNUserNotificationCenterDelegate>


@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    
    // 通知设置
    if (NSClassFromString(@"UNUserNotificationCenter")) {
        [UNUserNotificationCenter currentNotificationCenter].delegate = self;
    }
    
    // 全局配置
    [[AppConfig sharedAppConfig] globalSettings];

    // 证书名称 + 环信appkey值
    NSString *apnsCertName = nil;
#if DEBUG
    apnsCertName = @"Development";
#else
    apnsCertName = @"Production";
#endif

    NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
    
    NSString *appkey = [ud stringForKey:@"identifier_appkey"];
    if (!appkey) {
        appkey = EaseMobAPPKEY;
        [ud setObject:appkey forKey:@"identifier_appkey"];
    }

    [[EMClient sharedClient] addDelegate:self delegateQueue:nil];
    
    // 配置环信
    [self easemobApplication:application
didFinishLaunchingWithOptions:launchOptions
                      appkey:appkey
                apnsCertName:apnsCertName
                 otherConfig:@{kSDKConfigEnableConsoleLogger:[NSNumber numberWithBool:YES]}];
    
    

    
    
    
    
    self.window.rootViewController = [MainViewController bounceBarItems];
    
    
//    
//    [ZL_NetworkHelper POST:@"http://52.80.21.157:8888/server/userLogin/code4" parameters:@{@"phone":@"13168771430"} success:^(id responseObject) {
//        
//    } failure:^(NSError *error) {
//        
//    }];
//    
//    NSDictionary *params = @{
//                             @"phone":@"13168771430",
//                             @"code":@"1111",
//                             };
//    [ZL_NetworkHelper POST:@"http://52.80.21.157:8888/server/userLogin/appLoginPhoneCode" parameters:params success:^(id responseObject) {
//        
//    } failure:^(NSError *error) {
//        
//    }];
    
//    [[YConfig sharedYConfig] deleteData];
    
    
    
    
    
    
    
    
//
//    [ZL_NetworkHelper POST:@"http://52.80.21.157:8888/server/userLogin/appLogin" parameters:@{@"phone":@"13168771430",@"password":@"qq2017"} success:^(id responseObject) {
//        
//        
//        
//        
//        [[YConfig sharedYConfig] insertData:[[responseObject objectForKey:@"data"] pickID]];
//        
//        [ZL_NetworkHelper configRequestType:ZL_NetworkRequestTypeJSON];
//        
//        [ZL_NetworkHelper POST:@"http:/52.80.21.157:8888/server/user/save" parameters:@{@"nickname":@"sas"} success:^(id responseObject) {
//            NSLog(@"成功");
//        } failure:^(NSError *error) {
//            NSLog(@"失败");
//            
//        }];
//
//        [[YConfig sharedYConfig] searchData];
//
//    } failure:^(NSError *error) {
//        
//    }];
    
    
    
    
    
    return YES;
}

- (void)setconfig:(YConfig *)config {

    _config = config;
     

    [[NSNotificationCenter defaultCenter] postNotificationName:@"SET_USERINFO" object:nil];

}

-(UIWindow *)window {
    if (!_window) {
        _window = [[UIWindow alloc] initWithFrame:SCREEN_RECT];
        _window.backgroundColor = [UIColor whiteColor];
    }
    [_window makeKeyAndVisible];
    
    return _window;
}


#pragma make 收到远程通知
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {


}


#pragma make 远程消息将要弹出
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
{
    NSDictionary *userInfo = notification.request.content.userInfo;
    [self easemobApplication:[UIApplication sharedApplication] didReceiveRemoteNotification:userInfo];
}

#pragma make 收到远程消息弹出
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler{



}


- (void)applicationWillResignActive:(UIApplication *)application {
    
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    
    [[EMClient sharedClient] applicationDidEnterBackground:application];
    
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    [[EMClient sharedClient] applicationWillEnterForeground:application];
    
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
}







@end
